<html>
<head><meta charset="utf-8"><title>OUT_DIR from cargo check · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html">OUT_DIR from cargo check</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="190387974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190387974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emil Lauridsen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190387974">(Mar 12 2020 at 13:19)</a>:</h4>
<p>So I'm currently working on making the cargo check code provide OUT_DIR for packages that run a build script, and the actual interfacing with cargo is easy. I'm not sure about how to hook it up to the rest of rust-analyzer however.</p>
<p>I currently have a cargo package id (e.g. <code>gl 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)</code>) and an OUT_DIR path, but I'm not quite sure how to access and update the corresponding crate from <code>on_check_task</code> in <code>main_loop.rs</code>. If anybody with more experience in how the crate graph is stored inside a <code>WorldState</code> could point me in the right direction it would be appreciated.</p>
<p>Secondly I'd also love some input on how/when to schedule getting the OUT_DIR values. As we all know by know, cargo check isn't always that fast, so running it asynchronously is a must. I'm not quite sure when to launch it to get the OUT_DIR values however. Ideally we'd have a way to ask cargo for just the OUT_DIRs without having to check the entire world, but that's not the situation currently.</p>



<a name="190389358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190389358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190389358">(Mar 12 2020 at 13:33)</a>:</h4>
<p><span class="user-mention" data-user-id="212936">@Emil Lauridsen</span> , this may not be very related, but I noticed a suspicions thing in <code>rls</code> code. They <a href="https://github.com/rust-lang/rls/blob/521498cd95c1389ef208d256acd2a1e4ca618cf0/Cargo.toml#L33" target="_blank" title="https://github.com/rust-lang/rls/blob/521498cd95c1389ef208d256acd2a1e4ca618cf0/Cargo.toml#L33">depend on cargo</a> as a package. I am not sure how this works, maybe this could mean they can access <code>out-dir</code> api in their code (though I don't see any code doing exactly that)?</p>



<a name="190394692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190394692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190394692">(Mar 12 2020 at 14:23)</a>:</h4>
<p>the <code>WorldState</code> contains an <code>AnalysisHost</code>. I think you should be able to create an <code>AnalysisChange</code>, <code>set_crate_graph</code> on that and then <code>apply_change</code> on the analysis host.</p>



<a name="190473432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190473432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190473432">(Mar 13 2020 at 05:45)</a>:</h4>
<p><span class="user-mention" data-user-id="132829">@Christopher Durham</span>  have some idea what the steps of the general cache process should be,you may be interested.</p>
<p><a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/How.20to.20get.20.60Out-Dir.60/near/190024836" title="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/How.20to.20get.20.60Out-Dir.60/near/190024836">https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/How.20to.20get.20.60Out-Dir.60/near/190024836</a></p>



<a name="190473608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190473608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190473608">(Mar 13 2020 at 05:49)</a>:</h4>
<p>Keep in mind when I wrote that I was under the impression that a new <code>cargo check</code> wouldn't re-emit the build-script-executed message. I may be wrong there, and that should simplify the process.</p>



<a name="190473897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190473897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190473897">(Mar 13 2020 at 05:57)</a>:</h4>
<p>And there is a vscode api <a href="https://code.visualstudio.com/api/references/vscode-api#ExtensionContext" target="_blank" title="https://code.visualstudio.com/api/references/vscode-api#ExtensionContext">ExtensionContext</a> which provide some cache related directory api , which might be usefull too.</p>



<a name="190498191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190498191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emil Lauridsen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190498191">(Mar 13 2020 at 12:47)</a>:</h4>
<p>Check seems to always replay the build-script-executed events, so we luckily shouldn't need to worry about that</p>



<a name="190502857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190502857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emil Lauridsen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190502857">(Mar 13 2020 at 13:35)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> It looks to me like we have no way to identify a crate in the CrateGraph by the id/name we get from cargo, is that right? If so, how would you prefer going about storing such a mapping so that we can actually set OUT_DIR without blocking on the first cargo check?</p>



<a name="190502989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190502989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190502989">(Mar 13 2020 at 13:36)</a>:</h4>
<p>When we lower <code>cargo metadata</code> to crate graph, we can remmeber a mapping from package name/target name to CrateId</p>



<a name="190510791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190510791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emil Lauridsen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190510791">(Mar 13 2020 at 14:47)</a>:</h4>
<p>Okay I've almost got it working, just gotta figure out how the get/create a ExternSourceId for a path on the fly. This would all be a lot easier if OUT_DIR was available form <code>cargo metadata</code>, it's turning out a bit more dirty than I'd like, so looking forward to some feedback once I get the last bit going.</p>



<a name="190511311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190511311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190511311">(Mar 13 2020 at 14:52)</a>:</h4>
<p>The cargo issue for that is not very encouraging</p>



<a name="190513960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190513960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190513960">(Mar 13 2020 at 15:11)</a>:</h4>
<p><span class="user-mention" data-user-id="212936">@Emil Lauridsen</span> Currently <code>ExternSourceId</code> is just a re-wrapper of <code>SourceRooId</code>, such that :</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">extern_source_id</span><span class="w"> </span><span class="o">=</span><span class="w">  </span><span class="n">ExternSoruceId</span><span class="p">(</span><span class="n">source_root_id</span><span class="p">.</span><span class="mi">0</span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="190515855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190515855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emil Lauridsen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190515855">(Mar 13 2020 at 15:25)</a>:</h4>
<p>Form the code in <code>world.rs</code> ~L130 it seems to be a wrapped VfsRoot id, but that appears to use the same ids so I think I got it figured out</p>



<a name="190518900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/190518900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emil Lauridsen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#190518900">(Mar 13 2020 at 15:49)</a>:</h4>
<p>I created a draft PR with my current work: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/3582" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/3582">https://github.com/rust-analyzer/rust-analyzer/pull/3582</a></p>



<a name="191095462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/191095462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#191095462">(Mar 19 2020 at 10:44)</a>:</h4>
<p>Why is <code>rust-analyzer.cargoFeatures.loadOutDirsFromCheck</code> disabled by default? Can we enable it in the future?</p>



<a name="191095932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/191095932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#191095932">(Mar 19 2020 at 10:47)</a>:</h4>
<p>It slows down initial load a lot</p>



<a name="191096109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/191096109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#191096109">(Mar 19 2020 at 10:49)</a>:</h4>
<p>Oh, right. Maybe we can turn it on when we support changing workspace contents dynamically?</p>



<a name="191096150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/191096150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#191096150">(Mar 19 2020 at 10:49)</a>:</h4>
<p>And I assume that's only on the first load</p>



<a name="191159943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR%20from%20cargo%20check/near/191159943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emil Lauridsen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/OUT_DIR.20from.20cargo.20check.html#191159943">(Mar 19 2020 at 18:58)</a>:</h4>
<p>Would could do it lazily, the main blocker is how annoying (if even possible) adding a new VFS root and source roots on the fly. With that in place at some point, we could just run the initial <code>cargo check</code> in a thread like we run <code>cargo check</code> on save, and update the <code>OUT_DIR</code>s on the fly.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>